package com.designer.shapes
{
	
	public class Oval extends GeometricShape
	{
		public function Oval(lineColor:Number=0, lineThickness:Number=0, lineAlpha:Number=1, fillColor:Number=0, fillAlpha:Number=1, xStart:Number=0, yStart:Number=0, xFinal:Number=0, yFinal:Number=0) {
			super("oval", lineColor, lineThickness, lineAlpha, fillColor, fillAlpha, xStart, yStart, xFinal, yFinal);
			draw();
		}
		
		public override function draw():void
		{
			
			this.graphics.clear();
			
			this.graphics.lineStyle(1.0, lineColor, 1.0);
			this.graphics.beginFill(fillColor, 1.0);
			
			var angleDelta:Number = Math.PI / 4;
			var angle:Number = 0; 
			var angleMid:Number = 0;
			var xRadius:Number = wid/2;
			var yRadius:Number = hei/2;
			
			var distX:Number = xRadius / Math.cos(angleDelta/2);
			var distY:Number = yRadius / Math.cos(angleDelta/2);
			var ctrlX:Number;
			var ctrlY:Number;
			var anchorX:Number;
			var anchorY:Number;
			var xCenter:Number = xStart + xRadius;
			var yCenter:Number = yStart + yRadius;
			
			this.graphics.moveTo(xCenter + xRadius, yCenter);
			
			for (var i:Number = 0; i < 8; i++) {
				angle += angleDelta;
				angleMid = angle-(angleDelta/2);
				ctrlX = xCenter + Math.cos(angleMid)*(distX);
				ctrlY = yCenter + Math.sin(angleMid)*(distY);
				anchorX = xCenter + Math.cos(angle) * xRadius;
				anchorY = yCenter + Math.sin(angle) * yRadius;
				this.graphics.curveTo(ctrlX, ctrlY, anchorX, anchorY);
  			}

		}
	}
}